package com.xxc.batis.config

import com.xxc.common.anotation.POKO
import com.xxc.common.util.ApplicationProps
import com.xxc.batis.mapper.CrudMapper
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration
import org.slf4j.LoggerFactory
import org.springframework.boot.autoconfigure.AutoConfigureAfter
import org.springframework.context.annotation.*
import tk.mybatis.spring.mapper.MapperScannerConfigurer

import java.util.Properties

@Configuration
@AutoConfigureAfter(MybatisAutoConfiguration::class)
@POKO
class MyBatisConfig{

    private val logger = LoggerFactory.getLogger(MyBatisConfig::class.java)

    @Bean
    fun mapperScannerConfigurer(): MapperScannerConfigurer {
        val mapperScannerConfigurer = MapperScannerConfigurer()
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory")
        mapperScannerConfigurer.setBasePackage(ApplicationProps["mybatis.mapper.package"])
        val properties = Properties()
        properties.setProperty("mappers", CrudMapper::class.java.name)
        properties.setProperty("notEmpty", "false")
        properties.setProperty("IDENTITY", "MYSQL")
        properties.setProperty("ORDER", "BEFORE")
        mapperScannerConfigurer.setProperties(properties)
        return mapperScannerConfigurer
    }

}